<#include '/admin/header.html' >
<style type="text/css">

.table_search button{
	margin-top: 0px!important;
}
td input{
	border: none;
   	text-align: center;
    width: 40px;
}
.receiptsInputText{
    width: 35px;
    height: 20px;
    border: 1px solid #ccc;
    border-radius: 3px;
   	text-align:center;
   	
}

</style>
<div  class="admin-main">
   <div>
        <!--提示区域  -->
        <div class="page_explain">
            <h2>操作提示</h2>
            <ul>
                            	<li><span>·</span>管理当前分类下所有的文章管理，可以对当前分类下所有的文章进行添加，修改，删除操作</li>

            </ul>
        </div>
        <!--按钮操作  -->
        <div class="table_control">
        <input type="hidden" id="catid" value="${catid}">
            <div class="table_opera">
                <button type="button" id="catid" class="layui-btn layui-btn-primary " title="添加" onclick="newTab('添加文章','${ctx}/cms/admin/data/add.do?catid=${catid}')"><i class="icon iconfont icon-llalbumshopselectorcreate"></i></button>
                <button type="button" class="layui-btn layui-btn-primary " title="保存排序" onclick="updateSort()"><i class="icon iconfont icon-xuanze"></i></button>
                <button type="button" class="layui-btn layui-btn-primary " title="提示" id="explain"><i class="icon iconfont icon-tishi1"></i></button>
            </div>
          
            <!--搜索区域  -->
            <div class="table_search" style="line-height: 47px;">
             <input type="text" id="searchText" class="keysearch" placeholder="请在这里输入关键字" style="margin-top: 0px;height:25px;">
              <select name="searchField" style="height: 25px;">
               	<#list fieldList as field>
				<option value="${field.english_name}">${field.china_name}</option>
				</#list>
		      </select>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-small" id="data"><i class="layui-icon">&#xe615;</i></button>
            </div>
           
        </div>
    </div>
    
   <!--表格区域  -->
   <form id="dataForm">
    <table id="helpdata" class="layui-table site-table table-hover" style="width: 100%;" >
        <thead>
          <tr>     
            <th>id</th>
            <th>页面标题</th>
            <th>排序</th>
            <th>添加时间</th>
            <th>修改</th>
            <th>删除</th>
          </tr>
        </thead>

    </table>
    <div id="addBrand" ></div>
   </form>
</div>

<script>
var table;
$(function(){
	
	table = $('#helpdata').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        url: '${ctx}/cms/admin/data/list-json.do?catid=${catid}',
	    },
	    columns: [ //定义列
	        {data: null,"render": function(obj) {
	    	     return '<input type="hidden" name="dataids" value="'+obj.id+'" ><span>'+obj.id+'</span>';		
	    	}},      
	        {data: "page_title"},
	        {data: null,"render": function(obj) {
 	        	return '<input type="text" name="sorts"  class="receiptsInputText" value="'+obj.sort+'" id="sorts">';		
 	       	}},
	        {data: null,"render": function(obj) {
	        	if(obj.add_time==null){
	        		return "";
	        	}
	        	else{
	        		return getFormatDateByLong(obj.add_time, "yyyy-MM-dd");
	        	}
	       	}},
	       	{data: null,"render": function(data, type, row) {
	       		return "<a class='layui-btn layui-btn-small layui-btn-normal' name='change_btn' onclick=\"newTab('修改','${ctx}/cms/admin/data/edit.do?dataid="+data["id"]+"&catid="+$("#catid").val()+"')\")>编辑</a>";
	       	}},
	       	{data: null,"render": function(data, type, row) {
	        	return "<a class='layui-btn layui-btn-small layui-btn-danger' name='change_btn' onclick='del("+ row.id+ ")'><img catid='"+row.id+"' src='${ctx}/cms/admin/images/transparent.gif'>删除</a>"
	       	}}
	     ]
	});
	
	//搜索
	$("#data").click(function(){
		searchData(table);
	});
});

function searchData(table){
	var searchText = $("#searchText").val();
	var searchField = $("select[name='searchField']").val();
	var param = "&searchText="+searchText+"&searchField="+searchField;
	var url = table.ajax.url("${ctx}/cms/admin/data/list-json.do?catid=${catid}"+param);
	url.load();
}
//删除
function del(id){
	if(!confirm("确认要删除吗？")){	
		return ;
	}
	var options = {
			url : "${ctx}/cms/admin/data/delete.do?ajax=yes&dataid="+id+"&catid="+$("#catid").val(),
			type : "POST",
			dataType : 'json',
			success : function(result) {
				if(result.result==1){
				    $.Loading.success(result.message);
					table.ajax.url("${ctx}/cms/admin/data/list-json.do?catid="+$("#catid").val()).load();
// 					newTab('商城公告','${ctx}/cms/admin/data/list.do?catid=26');
				}
				if(result.result==0){
					$.Loading.error(result.message);
				}
			}
	};
	$('#dataForm').ajaxSubmit(options);	
}
function updateSort(){
	var t=$("#sorts").val();
	if(t==undefined){
		alert("目前该页面没有数据！");
		return;
	};
	
	var z= /^[0-9]*$/;
	if(!z.test(t)&&t!=undefined){
	   $.Loading.error("请输入数字！");
	   return;
	};
	
	var options = {
			url :"${ctx}/cms/admin/data/update-sort.do?ajax=yes"+"&catid="+$("#catid").val(),
			type : "POST",
			dataType : 'json',
			success : function(result) {				
			 	if(result.result==1){
			 		$.Loading.success("保存成功！！");
			 		location.reload()
			 	}
			 	if(result.result==0){
			 		$.Loading.error(result.message);
				}
			}
		};

	$("#dataForm").ajaxSubmit(options);		
}
</script>
<#include '/admin/footer.html' >
